package org.springframework.core.logger;

/**
 * @author:刘仁有
 * @desc:
 * @email:953506233@qq.com
 * @data:2019/11/11
 */
public abstract class AbstractLogger {
    protected static int INFO = 1;
    protected static int DEBUG = 2;
    protected static int ERROR = 3;
    protected int level;
    protected Class<?>clazz;
    protected AbstractLogger nextLogger;
    protected void setNextLogger(AbstractLogger nextLogger){
        this.nextLogger = nextLogger;
    }

    private void logMsg(int level,String msg){
        //符合记录条件，记录
        if(this.level<=level){
            write(msg,clazz);
        }
        //放行给下一个日志记录器
        if(nextLogger!=null){
            nextLogger.logMsg(level,msg);
        }
    }
    //info级别
    public void info(String msg){
        logMsg(INFO,msg);
    }
    //debug级别
    public void debug(String msg){
        logMsg(DEBUG,msg);
    }
    //error级别
    public void error(String msg){
        logMsg(ERROR,msg);
    }
    abstract protected void write(String msg,Class<?>clazz);
}
